<?php

	require_once "../../konfigurasi.php";
	
	koneksi_buka();
	
	if(isset($_GET['id'])){
		$id = $_GET['id'];
	}
	
	if(isset($_POST['id'])){
		$id = $_POST['id'];
	}
	
	if(isset($_GET['soal_id'])){
		$soal_id = $_GET['soal_id'];
	}
	
	if(isset($_POST['soal_id'])){
		$soal_id = $_POST['soal_id'];
	}
	
	if(isset($_POST['siswa'])){
		$siswa = $_POST['siswa'];
	}
	
	if(isset($_GET['siswa'])){
		$siswa = $_GET['siswa'];
	}
	
	$q_hasil = "select * from hasil_soal where soal_id=$soal_id and siswa=$siswa";
	if(mysql_fetch_array(mysql_query($q_hasil))){
		
		header("Location:../../hasil_latihan.php?soal_id=$soal_id");
	}else{
		$tgl_daftar = date("Y-m-d");
		$wkt = date("H:i:s");
		
		$q = "INSERT INTO hasil_soal
			(soal_id, siswa) 
			VALUES('$soal_id', '$siswa')";
		$result = mysql_query($q);
		if($result){
			
			session_start();
			$_SESSION['hasil'] = mysql_insert_id();
			header("Location:../../soal.php?soal_id=".$soal_id."&no=1");
		}else{
			echo 'failed query :'.$q ;
		}
	}
	
	
?>
